package com.wsollers.testutils;

import java.lang.reflect.Method;

public class AssertCodeExists {
    public static void assertCodeExists ( String objectName ) {
        boolean classFound = false;
        try {
            Class.forName ( objectName );
            classFound = true;
        } catch ( ClassNotFoundException e ) {}
        if ( !classFound ) {
            throw new AssertionError ( "Code [" + objectName + "] not found" );
        }
    }

    public static void assertMethodInCodeExists ( Class clazz, String methodName ) {
        boolean methodFound = false;
        for ( Method method : clazz.getMethods () ) {
            if ( method.getName().equals ( methodName ) ) {
                methodFound = true;
                return;
            }
        }

        if ( !methodFound ) {
            throw new AssertionError ( "method [" + methodName + "] not found" );
        }

    }

}